package com.axonactive.training.maganedbean;

import java.util.List;

import javax.annotation.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.inject.Inject;

import com.axonactive.training.model.Category;
import com.axonactive.training.model.Income;
import com.axonactive.training.service.CategoryService;
import com.axonactive.training.service.IncomeService;

@ManagedBean
@RequestScoped
public class IncomeBean {
	private Income income;
	private Long categoryId;
	
	@Inject
	IncomeService IncomeService;
	@Inject
	CategoryService categoryService;
	
	public List<Income> getIncomeList(){
		return IncomeService.getIncomeList();
	}
	
	public void saveIncome(){
		Category categorySelected = categoryService.getCategoryById(categoryId);
		income.setCategory(categorySelected);
		IncomeService.saveIncome(income);
	}

	public Income getIncome() {
		if(income == null){
			income = new Income();
		}
		return income;
	}

	public void setIncome(Income income) {
		this.income = income;
	}
	
	public Long getCategoryId() {
		return categoryId;
	}

	public void setCategoryId(Long categoryId) {
		this.categoryId = categoryId;
	}
	
	
}
